from django.db import models

class User(models.Model):
   first_name = models.CharField(max_length = 30)
   last_name = models.CharField(max_length = 30)
   email =models.EmailField()
   password = models.CharField(max_length=10)
   confirmpassword = models.CharField(max_length=10)
   phone = models.CharField(max_length = 30)
   isAttendee = models.BooleanField()
   isCreator = models.BooleanField()
   isAdmin = models.BooleanField()
   isEventModerator = models.BooleanField()
   isSystemModerator = models.BooleanField()
   def __unicode__(self):
        return self.first_name
	#def authenticate(self, username=None, password=None):
		#try:
		 # user = User.objects.get(username=username)
		  #if user.check_password(password):
			#return user
		#except User.DoesNotExist:
		  #return None

	#def get_user(self, user_id):
		#try:
		  #return User.objects.get(pk=user_id)
		#except User.DoesNotExist:
		  #return None
  
class LiveStream(models.Model):
    channel = models.CharField(max_length = 50)
    def __unicode__(self):
            return self.channel

class SocialMarketing (models.Model):
    twitterUrl = models.URLField()
    facebookUrl = models.URLField()
    hashTag = models.CharField(max_length = 70)

class Location(models.Model):
    name=models.CharField(max_length=255)
    def __unicode__(self):
        return self.name

class Template (models.Model):
    name= models.CharField(max_length=255)
    def __unicode__(self):
        return self.name

class Agenda(models.Model):
    title =  models.CharField(max_length = 20 )

class Activity(models.Model):
    description = models.CharField(max_length=300)
    startTime = models.TimeField()
    endTime = models.TimeField()
    agendaID = models.ForeignKey(Agenda)          

class List (models.Model):
    title = models.CharField(max_length = 100)
     
class Item (models.Model):
    title = models.CharField(max_length = 250)   
    completed = models.BooleanField()
    todo_list = models.ForeignKey(List)
    
class Components(models.Model):
    title=models.CharField(max_length=30)
    description=models.TextField()
    files=models.CharField(max_length=30)
    approved=models.BooleanField()
    rejected=models.BooleanField()
    
    def showFiles(self):
        return '<a href="%s">%s</a>' % (self.files, self.files)
    showFiles.allow_tags = True
    
#showFiles Documentation
#This method allows admin to view suggested components by clicking on the URL
#Args:
#
#Returns:
#clickable link to view the suggested components
#How to use the funtion:
#Type the localhost "localhost:8000/admin/ and click on the url of the component you want and view it
class Faq (models.Model):
    question = models.TextField()
    answer = models.TextField()
    def __unicode__(self):
        return self.question


class TermsAndCondition (models.Model):
    title = models.CharField(max_length=500)
    description = models.TextField()
    def __unicode__(self):
        return self.title
		
class NewAndUpdate (models.Model):
    title = models.CharField(max_length=500)
    description = models.TextField()
    def __unicode__(self):
        return self.title
   
		
class AboutUs (models.Model):
    title = models.CharField(max_length = 255)
    description = models.TextField()
    def __unicode__(self):
      return self.title 
	  
class Media(models.Model):
    photo = models.ImageField(upload_to='uploadPhoto')
    video = models.FileField(upload_to='uploadVideo')

class Category (models.Model):
    category_title = models.CharField(max_length = 255)
    
class Pages (models.Model):
    title = models.CharField(max_length = 255)
    description = models.TextField()
    category = models.ForeignKey(Category)
    
    def __unicode__ (self):
        return self.title
    
class Link (models.Model):
    url = models.URLField()
    
class Menu  (models.Model):
    title = models.CharField(max_length=30) 
    link = models.ForeignKey(Link)
    def __unicode__(self):
        return self.title

class Payment(models.Model):
    paymentAmount = models.CharField(max_length = 50)
    deadline = models.CharField(max_length = 50)
    editPayment = models.CharField(max_length = 50)
    editDeadline = models.CharField(max_length = 50)
    
class CreatorTemplate(models.Model):
    #Event Related Attributes
    name= models.CharField(max_length=255)
    startDate= models.DateField(default="2012-01-1")
    endDate= models.DateField(default="2012-01-1")
    startTime= models.TimeField(default= "00:00")
    endTime= models.TimeField(default= "00:00")
    eventName=models.TextField(max_length=255, default= " ")
    # Components
    payment=models.ForeignKey(Payment) 
    media=models.ForeignKey(Media)
    location=models.ForeignKey(Location)
    agenda=models.ForeignKey(Agenda)
    liveStream= models.ForeignKey(LiveStream)
    socialMarketing= models.ForeignKey(SocialMarketing)
    #Additional Template Related Attributes
    brideName = models.CharField(max_length=70, default=" ")
    groomName = models.CharField(max_length=70, default=" ")
    birthdayOwner = models.CharField(max_length=70, default= " ")
    singerName = models.CharField(max_length=70, default=" ")
    charityType = models.CharField(max_length=70, default=" ")
    def __unicode__(self):
        return self.name 


class Event(models.Model):
        template = models.ForeignKey(CreatorTemplate)    
        eventName= models.CharField(max_length=30)
        attending = list()
        maybe_attending = list()
        not_attending = list()
        paid_attendees = list()
        visitors = list()
        isPublic = models.BooleanField()
        isApproved = models.BooleanField()
        isRejected = models.BooleanField()
        creator = models.ForeignKey(User)
        visibility = models.BooleanField()
        count_share=models.IntegerField()
        date = models.DateField(default="2013-01-1")
        
    #Dalia Hosny's
        eventLocation = models.CharField(max_length=100)
        eventTag = models.CharField(max_length=100)
        eventCategory = models.CharField(max_length=100)

        
        #users = models.ManyToManyField(User, through='attend_event', related_name="attending")
       # eventID = models.IntegerField(unique = True)
    
      #  def __init__(self, name = "", isPublic = 0, isApproved = 0 ):
       #     self.eventName = name
        #    self.isPublic = isPublic
         #   self.isApproved = isApproved
            
       # def __unicode__(self):
        #    return self.eventName
        
        
                
class PageCounter(models.Model):
    event = models.ForeignKey(Event)
    pageCounter = models.IntegerField()
    
class LikeEvent(models.Model):
    user=models.ForeignKey(User)
    event=models.ForeignKey(Event)

        
class PayedAttendees (models.Model):
    user = models.ForeignKey(User)
    event = models.ForeignKey(Event)
    

    
class Attending(models.Model):
    user = models.ForeignKey(User) 
    event = models.ForeignKey(Event)
    
class MaybeAttending(models.Model):
    user = models.ForeignKey(User)
    event = models.ForeignKey(Event)
    
class NotAttending(models.Model):
    user = models.ForeignKey(User)
    event = models.ForeignKey(Event)
    
class Visitor(models.Model):
    user = models.ForeignKey(User)
    event = models.ForeignKey(Event)
    
class Invited(models.Model):
    user = models.ForeignKey(User)
    event = models.ForeignKey(Event)
class KnowledgeStore(models.Model):
    title= models.CharField(max_length=100)
    description= models.TextField()
    vedioTitle=models.CharField(max_length=100)
    link= models.URLField(max_length = 200)
    
    def __unicode__(self):
        return self.title

class CreatorTemplate(models.Model):
    name= models.CharField(max_length=255)
    startDate= models.DateField(default="2012-01-1")
    endDate= models.DateField(default="2012-01-1")
    startTime= models.TimeField(default= "00:00")
    endTime= models.TimeField(default= "00:00")
    eventName=models.TextField(max_length=255, default= "My Event ")
    payment=models.ForeignKey(Payment) 
    media=models.ForeignKey(Media)
    location=models.ForeignKey(Location)
    agenda=models.ForeignKey(Agenda)
    #liveStream= models.ForeignKey(LiveStream)
    #socialMarketing= models.ForeignKey(SocialMarketing)
    brideName = models.CharField(max_length=70, default=" ")
    groomName = models.CharField(max_length=70, default="   ")
    birthdayOwner = models.CharField(max_length=70, default= "   ")
    singerName = models.CharField(max_length=70, default="   ")
    charityType = models.CharField(max_length=70, default="   ")
    
    def __unicode__(self):
        return self.name 

class SelectedComponents (models.Model):
    template = models.ForeignKey(CreatorTemplate)
    name= models.CharField(max_length=70)
    def __unicode__(self):
        return self.name 

